﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Evaluation3.classes;

public partial class uicontrol_ChangePass : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnChange_Click(object sender, EventArgs e)
    {
        SqlDataSource dsPass = new SqlDataSource(ConfigurationManager.ConnectionStrings["evaConn"].ToString(), "SELECT * FROM Users WHERE TenTruyCap='" + ((remoteUser)Session["remoteUser"]).uName + "'");
        if (((DataView)dsPass.Select(DataSourceSelectArguments.Empty)).Table.Rows.Count > 0 && ((DataView)dsPass.Select(DataSourceSelectArguments.Empty)).Table.Rows[0]["MatKhau"].ToString() == txtOldPass.Text.Trim())
        {
            dsPass.UpdateCommand = "UPDATE Users SET MatKhau = '" + txtNewPass.Text.Trim() + "' WHERE TenTruyCap = '" + ((remoteUser)Session["remoteUser"]).uName + "'";
            dsPass.Update();

            lblNotify.Text = "Đổi mật khẩu thành công";
            lblError.Text = "";
        }
        else
        {
            lblError.Text = "Mật khẩu cũ của bạn không đúng.";
            lblNotify.Text = "";
        }

        dsPass.Dispose();
    }
    protected void btnCancel_Click(object sender, EventArgs e)
    {
        txtNewPass.Text = "";
        txtNewPassAgain.Text = "";
        txtOldPass.Text = "";
        lblError.Text = "";
        lblNotify.Text = "";
    }
}
